package com.aioz.controller;

import com.aioz.annotation.RedisLockAnnotation;
import com.aioz.service.impl.GoodsServiceImpl;
import com.aioz.utils.RedisLockTypeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    private static final Logger log = LoggerFactory.getLogger(GoodsController.class);

    @Resource
    private GoodsServiceImpl goodsService;

    @GetMapping("/purchase")
    @RedisLockAnnotation(typeEnum = RedisLockTypeEnum.DELIVERY, lockTime = 3)
    public void purchaseGoods(@RequestParam("userId") Long userId,
                              @RequestParam("goodsId") Integer goodsId){
        log.info("ID:  {} 的用户开始下单 购买物品ID:  {}",userId,goodsId);
        goodsService.purchaseGoods(userId,goodsId);
    }
}
